<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page language="java" import="com.server.web.JsVersionUtil"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>${projectName}</title>
<script type="text/javascript"
	src='<c:url value="/js/boot.js"></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>'></script>
<script src="<c:url value='/js/jquery.ui.widget.js'></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>"></script>
<script src="<c:url value='/js/jquery.fileupload.js'></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>"></script>
<script src="<c:url value='/js/server/rqfCommon.js'></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>"></script>
<link rel="stylesheet" type="text/css"
	href='<c:url value="/share/styles.css"></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>' />
<style type="text/css">
body {
	height: 100%;
}

.fieldTitle {
	width: 100px !important;
}

.mini-tabs-leftButton, .mini-tabs-rightButton {
	display: none;
}

.mini-tabs-scrollCt {
	border-top: 0;
}

.mini-tabs-bodys {
	padding: 0;
}

.headerpan {
	margin-left: 10px;
	font-size: 14px;
	font-weight: bold;
}
#UserPhoto{
	background-image: url('<c:url value="/share/images/test.jpg"></c:url>');
	background-size:150px 210px;
	width:150px;
	height: 210px;
	vertical-align: middle;
	margin-left:auto; 
	margin-right:auto;
}
.photoStyle{
	background-size:150px 210px;
	width:150px;
	height: 210px;
	vertical-align: middle;
	margin-left:auto; 
	margin-right:auto;
}
.cardStyle{
	background-size:210px 120px;
	width:210px;
	height: 120px;
	vertical-align: middle;
	margin-left:auto; 
	margin-right:auto;
}

#headimg {
	margin-left:auto; 
	margin-right:auto;
	width: 150px;
	height: 210px;
	/* border:1px solid #ccc; */
	background-size: 100%;
}

.cardimg {
	margin-left:auto; 
	margin-right:auto;
	width: 100%;
	height: 120px;
	/* border:1px solid #ccc; */
	background-size: 100%;
}

#change_head_btn,#id_card_a,#id_card_b {
	width: 75px;
	height: 20px;
	color: white;
	text-align: center;
	margin-left: auto;
	margin-right: auto;
	margin-top: 5px;
}

.file {
	position: relative;
	display: inline-block;
	background: #1e519f;
	/*border: 1px solid #99D3F5;*/
	border-radius: 4px;
	/* padding: 4px 12px; */
	overflow: hidden;
	color: #1E88C7;
	text-decoration: none;
	text-indent: 0;
	line-height: 20px;
	cursor: pointer !important;
}
.file input {
	position: absolute;
	font-size: 100px;
	right: 0;
	top: 0;
	opacity: 0;
	cursor: pointer;
}

.file:hover {
	background: #ccc;
	text-decoration: none;
}
.id_card_style{
	width: 100%;
	height: 140px;
}

</style>
<script type="text/javascript">
	var sexData = [ {
		id : 1,
		text : "男"
	}, {
		id : 0,
		text : "女"
	} ];
	var natureData = [ {
		id : 1,
		text : "长期"
	}, {
		id : 0,
		text : "短期"
	} ];
</script>
</head>
<body>
	<form id="dataForm">
		<div class="formContent">
			<input id="OrgNo" name="OrgNo" class="mini-hidden"
				style="width: 100%;" />
			<input id="EmployId" name="EmployId" class="mini-hidden"
				style="width: 100%;" />
			<table class="formContentTable type1" id="type1">
				<span class="headerpan type1">基本信息</span>
				<tr>
					<th class="fieldTitle"></th>
					<th class="fieldContent"></th>
					<th class="fieldTitle"></th>
					<th class="fieldContent"></th>
				</tr>
				<tr>
					<td class="fieldTitle">身份证号</td>
					<td class="fieldContent" colspan="2"><input id="CardID"
						name="CardID" class="mini-textbox" style="width: 100%;"
						required="true" onblur="cardCheck"/></td>
					<td class="photoTd" rowspan="8"><div id="headimg"
							style="border: 1px solid #ccc;"><a href="javascript:;">
							<img src="<c:url value='/share/images/photo_1.jpg'></c:url>"
								id="imgUrl" alt="" class="photoStyle" /></a>
						</div>
						<a href="javascript:;" class="file" id="change_head_btn">上传照片
							<input
							accept="image/png,image/bmp,image/jpeg,image/gif,image/jpg"
							name="file" type="file" id="fileId" />
					</a></td>
					<!-- <td class="photoTd" rowspan="8"><a href="javascript:;"><div
						id="UserPhoto" onclick="javascript:addPhoto()"></div></a></td> -->
				</tr>
				<tr>
					<td class="fieldTitle">姓名</td>
					<td class="fieldContent" colspan="2"><input id="UserName"
						name="UserName" class="mini-textbox" style="width: 100%;"
						required="true" /></td>
				</tr>
				<tr>
					<td class="fieldTitle">性别</td>
					<td class="fieldContent" colspan="2"><input name="Sex"
						required="false" class="mini-combobox" id="Sex"
						style="width: 100%;" textField="text" valueField="id"
						data="sexData" showNullItem="true" 
						emptyText="保密" allowInput="true" onvaluechanged="" /></td>
				</tr>
				<tr>
					<td class="fieldTitle">出生日期</td>
					<td class="fieldContent" colspan="2"><input id="BirthDay"
						enabled="true" name="BirthDay" class="mini-datepicker"
						style="width: 100%;" /></td>
				</tr>
				<tr>
					<td class="fieldTitle">原户籍地</td>
					<td class="fieldContent" colspan="2"><input name="Province"
						required="false" class="mini-combobox" id="Province"
						style="width: 30%;" textField="Province" valueField="ProvinceID"
						url="<c:url value='/common/province' />" showNullItem="true"
						emptyText="保密" allowInput="true" onvaluechanged="changeProvince" 
						onitemclick=""/>
						<input
						name="City" required="false" class="mini-combobox"
						id="City" style="width: 30%;" textField="City"
						valueField="CityID" url="" showNullItem="true" emptyText="保密"
						allowInput="true" onvaluechanged="changeCity" 
						onitemclick=""/>
						<input
						name="Area" required="false" class="mini-combobox"
						id="Area" style="width: 30%;" textField="Area"
						valueField="AreaID" url="" showNullItem="true" emptyText="保密"
						allowInput="true" onvaluechanged="" /></td>
				</tr>
				<tr>
					<td class="fieldTitle">户籍地详细</td>
					<td class="fieldContent" colspan="2"><input id="Registry"
						name="Registry" class="mini-textbox" style="width: 100%;"
						required="false" enabled="true"/></td>
				</tr>
				<tr>
					<td class="fieldTitle">现居住地</td>
					<td class="fieldContent" colspan="2"><input id="Residence"
						name="Residence" class="mini-textbox" style="width: 100%;"
						required="false" enabled="true"/></td>
				</tr>
				<tr>
					<td class="fieldTitle">手机号码</td>
					<td class="fieldContent" colspan="2"><input id="PhoneNo"
						name="PhoneNo" class="mini-textbox" style="width: 100%;"
						required="false" enabled="true" onblur="phoneCheck"/></td>
				</tr>
				<tr>
					<td class="fieldTitle">邮箱</td>
					<td class="fieldContent" colspan="2"><input id="Email"
						name="Email" class="mini-textbox" style="width: 100%;"
						required="false" enabled="true"/></td>
				</tr>
				<tr>
					<td class="fieldTitle">紧急联系人</td>
					<td class="fieldContent"><input id="LinkMan"
						name="LinkMan" class="mini-textbox" style="width: 100%;"
						required="false" enabled="true"/></td>
					<td class="fieldTitle">联系方式</td>
					<td class="fieldContent"><input id="LinkManCall"
						name="LinkManCall" class="mini-textbox" style="width: 100%;"
						required="false" enabled="true"/></td>
				</tr>
				<!-- <tr>
					<td class="fieldTitle">紧急联系人</td>
					<td class="fieldContent" colspan="3"><textarea id="Linkman"
							name="Linkman" style="width: 100%; height: 80px;"
							required="false" class="mini-textarea" emptyText="输入紧急联系人及联系方式"></textarea></td>
				</tr> -->
				<tr>
					<td class="fieldTitle">身份证正面</td>
					<td class="id_card_style"><div class="cardimg"
							style="border: 1px solid #ccc;"><a href="javascript:;">
							<img src="<c:url value='/share/images/id_cardA_1.jpg'></c:url>"
								id="imgUrlA" alt="" class="cardStyle" /></a>
						</div>
						<a href="javascript:;" class="file" id="id_card_a">上传
							<input
							accept="image/png,image/bmp,image/jpeg,image/gif,image/jpg"
							name="fileA" type="file" id="fileIdA" />
					</a></td>
					<td class="fieldTitle">身份证反面</td>
					<td class="id_card_style"><div class="cardimg"
							style="border: 1px solid #ccc;"><a href="javascript:;">
							<img src="<c:url value='/share/images/id_cardB_1.jpg'></c:url>"
								id="imgUrlB" alt="" class="cardStyle" /></a>
						</div>
						<a href="javascript:;" class="file" id="id_card_b">上传
							<input
							accept="image/png,image/bmp,image/jpeg,image/gif,image/jpg"
							name="fileB" type="file" id="fileIdB" />
					</a></td>
				</tr>
			</table>
			<table class="formContentTable type1" id="type2">
				<span class="headerpan type1">入职登记</span>
				<tr>
					<th class="fieldTitle"></th>
					<th class="fieldContent"></th>
					<th class="fieldTitle"></th>
					<th class="fieldContent"></th>
				</tr>
				<tr>
					<td class="fieldTitle">企业名称</td>
					<td class="fieldContent"><input id="OrgName"
						name="OrgName" class="mini-textbox" style="width: 100%;"
						required="true" enabled="false"/></td>
					<td class="fieldTitle">入职时间</td>
					<td class="fieldContent"><input id="EmployTime"
						enabled="true" name="EmployTime" class="mini-datepicker"
						style="width: 100%;" onvaluechanged="changePolicy"/></td>
				</tr>
				<tr>
					<td class="fieldTitle">来源分类</td>
					<td class="fieldContent"><input name="SourceType"
						id="SourceType" required="true" class="mini-combobox"
						style="width: 100%;" textField="SourceType" valueField="Id"
						url="<c:url value='/common/type/source_type'></c:url>" showNullItem="false" allowInput="false" 
						onvaluechanged="typeChange" /></td>
					<td class="fieldTitle">来源</td>
					<td class="fieldContent"><input name="Source" 
						id="Source" required="true" class="mini-combobox"
						style="width: 100%;" textField="UserName" valueField="CardID"
						url="" showNullItem="true" allowInput="true" onvalidation="onComboValidation"
						onvaluechanged="" /></td>
				</tr>
				<tr>
					<td class="fieldTitle">性质</td>
					<td class="fieldContent"><input name="Nature"
						id="Nature" class="mini-combobox"
						style="width: 100%;" textField="text" valueField="id"
						data="natureData" showNullItem="false" allowInput="false"
						onvaluechanged="changePolicy" required="false"/></td>
					<td class="fieldTitle">工种</td>
					<td class="fieldContent"><input name="EmployType"
						id="EmployType" required="false" class="mini-combobox"
						style="width: 100%;" textField="EmployType" valueField="TypeNo"
						url="<c:url value='/common/type/employ_type'></c:url>" showNullItem="false" allowInput="false"
						onvaluechanged="" /></td>
				</tr>
				<tr>
					<td class="fieldTitle">返费政策</td>
					<td class="fieldContent" colspan="3"><input name="Policy"
						id="Policy" class="mini-combobox" 
						style="width: 100%;" textField="RewardText" valueField="Id"
						showNullItem="false" allowInput="false"
						onvaluechanged="" required="true"/></td>
				</tr>
			</table>
			<table class="formContentTable type1" id="type3">
				<span class="headerpan type1">资金账号</span>
				<tr>
					<th class="fieldTitle"></th>
					<th class="fieldContent"></th>
					<th class="fieldTitle"></th>
					<th class="fieldContent"></th>
				</tr>
				<tr>
					<td class="fieldTitle">支付宝账号</td>
					<td class="fieldContent" colspan="3"><input id="AlipayNo"
						name="AlipayNo" class="mini-textbox" style="width: 100%;"
						required="false" enabled="true"/></td>
				</tr>
				<tr>
					<td class="fieldTitle">微信账号</td>
					<td class="fieldContent" colspan="3"><input id="WechartNo"
						name="WechartNo" class="mini-textbox" style="width: 100%;"
						required="false" enabled="true"/></td>
				</tr>
				<tr>
					<td class="fieldTitle">银行卡号</td>
					<td class="fieldContent" colspan="3"><input id="BankNo"
						name="BankNo" class="mini-textbox" style="width: 100%;"
						required="false" enabled="true"/></td>
				</tr>
			</table>
			<table class="formContentTable type1" id="type4">
				<span class="headerpan type1">其他信息</span>
				<tr>
					<th class="fieldTitle"></th>
					<th class="fieldContent"></th>
					<th class="fieldTitle"></th>
					<th class="fieldContent"></th>
				</tr>
			</table>
		</div>
	</form>

	<script type="text/javascript">
		mini.parse();
		mini_debugger = false;
		
		var rootPath = parent.getRootPath();
		var userName = parent.getUserName();
		var action = parent.getAction();
		var orgNo = parent.getOrgNo();
		var fileServer = parent.getFileServer();
		var id = parent.getId();
		var configStr = parent.getConfigStr();
		var dataOri = null;
		var orgName = parent.parent.orgName;
		
		var CardID = mini.get("CardID");
		var Source = mini.get("Source");
		var SourceType = mini.get("SourceType");
		var Nature = mini.get("Nature");
		var OrgNo = mini.get("OrgNo");
		var OrgName = mini.get("OrgName");
		var BirthDay = mini.get("BirthDay");
		var Sex = mini.get("Sex");
		var Province = mini.get("Province");
		var City = mini.get("City");
		var Area = mini.get("Area");
		var EmployTime = mini.get("EmployTime");
		var Policy = mini.get("Policy");
		
		
		if(configStr){
			$('#type4').append(configStr);
		}else{
			$('#type4').hide();
		}

		if (parent.hideAtt) {
			parent.hideAtt();
		
		}

		function onComboValidation(e) {
			var value = e.value;
			if (!value) {
				this.setValue();
				return;
				/* e.isValid = false;
				e.errorText = "输入值不在下拉数据中!"; */
			}
			var items = this.findItems(value);
			if (!items || items.length == 0) {
				e.isValid = false;
				e.errorText = "输入值不在下拉数据中!";
			}
		}
		function typeChange(){
			changePolicy();
			var value = this.value;
			var url1 = "<c:url value='/user/source/'></c:url>"+value;
			Source.load(url1);
		}

		var form = new mini.Form("dataForm");

		SetFormData();

		function SetFormData() {
			changePolicy();
			if (action == "new") {
				$('#change_head_btn').hide();
				$('#id_card_a').hide();
				$('#id_card_b').hide();
				
				/* var url2 = "<c:url value='/common/type/source_type'></c:url>";
				mini.get("SourceType").load(url2);
				var url3 = "<c:url value='/common/type/employ_type'></c:url>";
				mini.get("EmployType").load(url3); */
				var o = new Object();
				o.OrgNo = orgNo;
				o.OrgName = orgName;
				
				var eDate = new Date();
				eDate.setHours(0);
				eDate.setMinutes(0);
				eDate.setSeconds(0);
				eDate.setMilliseconds(0);
				o.EmployTime = eDate;
				
				form.setData(o);
				dataOri = o;
				return;
			}
			if(action == "check"){
				$('#change_head_btn').hide();
				$('#id_card_a').hide();
				$('#id_card_b').hide();
			}
			CardID.disable();
			Source.disable();
			SourceType.disable();
			Nature.disable();
			Policy.disable();
			//EmployTime.disable();
			var messageid = mini.loading("获取中...", "Loading");
			var urlBase = '<c:url value="/user/form/"></c:url>' + id;
			$.ajax({
				url : urlBase,
				type : "get",
				dataType : 'json',
				success : function(text) {
					if (!text) {
						return;
					}
					console.info(text);
					var o = mini.decode(text);
					var url1 = "<c:url value='/user/source/'></c:url>"+o.SourceType;
					Source.load(url1);
					var photoUrl = o.UserPhoto;
					if(photoUrl){
						$("#imgUrl").attr("src",fileServer + photoUrl);
					}else{
						$("#imgUrl").attr("src","<c:url value='/share/images/photo_2.jpg'></c:url>");
					}
					var cardA = o.CardA;
					if(cardA){
						$("#imgUrlA").attr("src",fileServer + cardA);
					}else{
						$("#imgUrlA").attr("src","<c:url value='/share/images/id_cardA_2.jpg'></c:url>");
					}
					var cardB = o.CardB;
					if(cardB){
						$("#imgUrlB").attr("src",fileServer + cardB);
					}else{
						$("#imgUrlB").attr("src","<c:url value='/share/images/id_cardB_2.jpg'></c:url>");
					}
					form.setData(o);
					orgNo = o.OrgNo;
					changeProvince();
					changeCity();
					Policy.setValue(o.RewardId);
					loadUserRewardPolicy(o.RewardId);
					dataOri = o;
					parent.labelModel(form);
				},
				complete : function(XMLHttpRequest, textStatus) {
					mini.hideMessageBox(messageid);
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {

				}
			});
		}
		function packData() {
			return form;
		}
		function parentChanged() {
			var value = ParentName.getValue();
			var object = value.split('serverSplit');
			ParentNo.setValue(object[0]);
		}
		//添加头像
		function addPhoto(){
			if(action == "new"){
				top.commonTools.showTip("请保存信息后再上传照片！", 2);
				return;
			}
			var cardId = dataOri.CardID;
			$('#fileId').fileupload({
				dataType : 'html',//数据类型：json
				url : rootPath + 'attach/upload/file/无/photo/'+cardId,//上传地址
				formData : {
					name : 'file'
				},
				add : function(e, data) {
					data.submit();
				},
				done : function(e, data) {
					var param = successDataTransform(data.result);
					if (param.isSuccess) {
						$("#imgUrl").attr("src",
								fileServer + param.errorInfo);
					}
				}
			});
		}
		// 修改头像
		$("#change_head_btn").click(function() {
			var cardId = dataOri.CardID;
			$('#fileId').fileupload({
				dataType : 'html',//数据类型：json
				url : rootPath + 'attach/upload/file/无/UserPhoto/'+cardId,//上传地址
				formData : {
					name : 'file'
				},
				add : function(e, data) {
					data.submit();
				},
				done : function(e, data) {
					var param = successDataTransform(data.result);
					if (param.isSuccess) {
						$("#imgUrl").attr("src",fileServer + param.errorInfo);
					}
				}
			});
		});
		// 身份证正面
		$("#id_card_a").click(function() {
			var cardId = dataOri.CardID;
			$('#fileIdA').fileupload({
				dataType : 'html',//数据类型：json
				url : rootPath + 'attach/upload/fileA/无/CardA/'+cardId,//上传地址
				formData : {
					name : 'fileA'
				},
				add : function(e, data) {
					data.submit();
				},
				done : function(e, data) {
					var param = successDataTransform(data.result);
					if (param.isSuccess) {
						$("#imgUrlA").attr("src",fileServer + param.errorInfo);
					}
				}
			});
		});
		// 身份证反面
		$("#id_card_b").click(function() {
			var cardId = dataOri.CardID;
			$('#fileIdB').fileupload({
				dataType : 'html',//数据类型：json
				url : rootPath + 'attach/upload/fileB/无/CardB/'+cardId,//上传地址
				formData : {
					name : 'fileB'
				},
				add : function(e, data) {
					data.submit();
				},
				done : function(e, data) {
					var param = successDataTransform(data.result);
					if (param.isSuccess) {
						$("#imgUrlB").attr("src",fileServer + param.errorInfo);
					}
				}
			});
		});
		function cardCheck(e){
			var value = this.value;
			var length = value.length;
			if(value && length != 18){
				top.commonTools.showTip("身份证号长度有误，请检查！", 2);
				this.focus ();
				return;
			}
			//1.检测该员工数据是否存在及是否在职
			var messageid = mini.loading("信息验证中...", "Loading");
			var urlBase = '<c:url value="/user/info/"></c:url>' + value;
			$.ajax({
				url : urlBase,
				type : "get",
				dataType : 'json',
				success : function(text) {
					if (!text || $.isEmptyObject(text)) {//没有员工信息
						var birth = value.substr(6,8);
						BirthDay.setValue(birth);
						var sex = parseInt(value.substr(16,1))%2;
						Sex.setValue(sex);
						var province = value.substr(0,2);
						var city = value.substr(0,4);
						var area = value.substr(0,6);
						Province.setValue(province+"0000");
						changeProvince();
						City.setValue(city+"00");
						changeCity();
						Area.setValue(area);
					}else{//信息已存在
						var o = mini.decode(text);
						var state = o.State;
						if(state){
							if(o.OrgNo == orgNo){
								//已在职
								top.commonTools.showTip("在职员工不得重复入职！", 2);
							}else{
								top.commonTools.showTip("该员工已在其他公司入职！", 2);
							}
							CardID.focus ();
							return ;
						}
						var url1 = "<c:url value='/user/source/'></c:url>"+o.SourceType;
						Source.load(url1);
						var photoUrl = o.UserPhoto;
						if(photoUrl){
							$("#imgUrl").attr("src",fileServer + photoUrl);
						}else{
							$("#imgUrl").attr("src","<c:url value='/share/images/photo_2.jpg'></c:url>");
						}
						var cardA = o.CardA;
						if(cardA){
							$("#imgUrlA").attr("src",fileServer + cardA);
						}else{
							$("#imgUrlA").attr("src","<c:url value='/share/images/id_cardA_2.jpg'></c:url>");
						}
						var cardB = o.CardB;
						if(cardB){
							$("#imgUrlB").attr("src",fileServer + cardB);
						}else{
							$("#imgUrlB").attr("src","<c:url value='/share/images/id_cardB_2.jpg'></c:url>");
						}
						o.OrgNo=orgNo;
						o.OrgName=orgName;
						
						var eDate = new Date();
						eDate.setHours(0);
						eDate.setMinutes(0);
						eDate.setSeconds(0);
						eDate.setMilliseconds(0);
						o.EmployTime = eDate;
						
						form.setData(o);
						
						changeProvince();
						changeCity();
						dataOri = o;
					}
				},
				complete : function(XMLHttpRequest, textStatus) {
					mini.hideMessageBox(messageid);
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {

				}
			});
		}
		function phoneCheck(e){
			var phone = this.value;;
		    if(phone && !(/^1[34578]\d{9}$/.test(phone))){ 
		    	top.commonTools.showTip("手机号码有误，请重新输入！", 2);
				this.focus ();
				return;
		    } 
		}
		function changeProvince(){
			var value = Province.getValue();
			if(!value) return;
			City.load("<c:url value='/common/city/' />"+value);
		}
		function changeCity(){
			var value = City.getValue();
			if(!value) return;
			Area.load("<c:url value='/common/area/' />"+value);
		}
		function changePolicy(){
			var employTime = EmployTime.getValue();
			var nature = Nature.getValue();
			var sourceType = SourceType.getValue();
			if(!employTime) employTime=new Date();
			if(!nature) nature = "null";
			if(!sourceType) sourceType="null";
			Policy.load("<c:url value='/common/rewardPolicy/' />"+orgNo+"/"+nature+"/"+sourceType+"/"+employTime);
		}
		function loadUserRewardPolicy(rewardId){
			Policy.load("<c:url value='/common/rewardPolicyDetail/' />"+rewardId);
		}
	</script>
</body>
</html>